<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@include file="../commons/taglibs.jsp" %>
<%@include file="../commons/jquery-validation.jsp" %>
<style type="text/css">
	.msgred{
		color:red;
		padding-top:4px;
	}
</style>
<script type="text/javascript">
	$(function(){
		$("#updPwd").click(function(){
			$("#frm").submit();
		});
		$("#frm").validate({
			//验证通过提交表单
			submitHandler:function(form){
				var dataPwd={oldPwd:$("#oUserPwd").val(),newPwd:$("#userPwd").val()};
				 $.post(base+"/user/updPwd",dataPwd,function(data){
					 $("#updPwd").button('reset');//重置提交按钮 
					 gDialog.fClose();
					 if(data=="succeed"){//修改成功
						message_box.show('<h4>成功</h4>密码修改成功!','success');
					 }else{
						message_box.show('<h4>失败</h4>'+data,"error");
					 }
				},"text");
			},
		     rules: {
		    	 "oUserPwd": {
		    	    required: true,
		    	    remote:{//远程验证原密码是否正确
		    	        url:base+"/user/checkPwd",
		    	        type: "post",               //数据发送方式
		    	        dataType: "json",           //接受数据格式   
					    data: {                     //要传递的数据
					    	oUserPwd:function() {
					            return $("#oUserPwd").val();
					       }
					    }
		    	    }
		    	 },
		    	 "nUserPwd": {
			    	required: true,
			    	minlength: 3
			     },
		    	 "userPwd": {
			    	required: true,
			    	equalTo:"#nUserPwd"
			     },
		    },
		     messages: {
		    	 "oUserPwd": {
		    	   required: "* 请输入原密码！",
		    	   remote:"* 原密码不正确！"
		    	 },
			    "nUserPwd": {
			    	required: "* 请输入新密码！",
			    	minlength:"* 密码长度不能小于{0}个字 符"

			    },
			    "userPwd": {
			    	required: "* 请再次输入新密码！",
			    	equalTo:"* 二次输入的密码不相同"
			    }
		    },
		    errorPlacement:function(error, element) {//设置提示消息位置
		    	error.appendTo( element.parent().next());
		    },
		    success: function(label) {//验证通过插入通过图标
		    	label.html("<i class='fa fa-check' style='color:#8CBF00;'></i>");
		    }
		 });
	});
</script>
<div class="modal-body">
	<div class="container-fluid">
		<form id="frm" method="POST" class="form-horizontal" role="form">
			<input type="hidden" value="${user.id}" id="id" name="id">
			<div class="row-fluid">
			  <div class="col-sm-12">	
				<div class="form-group">
					<label for="oUserPwd" class="col-sm-3 control-label">原密码：</label>
					<div class="col-sm-5">
						<input class="form-control" id="oUserPwd"  name="oUserPwd" type="password"/>
					</div>
					<label class="col-sm-4 msgred"></label>
				</div>
			  </div>
			</div>
			<div class="row-fluid">
			  <div class="col-sm-12">		
				<div class="form-group">
					<label for="nUserPwd" class="col-sm-3 control-label">新密码：</label>
					<div class="col-sm-5">
						<input class="form-control" id="nUserPwd" name="nUserPwd" type="password" />
					</div>
					<label class="col-sm-4 msgred"></label>
				</div>
			  </div>
			</div>
			<div class="row-fluid">
			  <div class="col-sm-12">
				<div class="form-group">
					<label for="userPwd" class="col-sm-3 control-label">确认密码：</label>
					<div class="col-sm-5">
						<input class="form-control" id="userPwd" name="userPwd" type="password"/>
					</div>
					<label class="col-sm-4 msgred"></label>
				</div>
			  </div>
			</div>
		</form>
	</div>
</div>
<div class="modal-footer">
	<a class="btn btn-success" id="updPwd" data-loading-text="提交中...">保存修改</a>
	<a class="btn btn-default" onclick="gDialog.fClose();">关闭</a>
</div>